﻿using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.fastOLV.AllowColumnReorder = true;
            this.fastOLV.RowHeight = 30;//行高
            this.fastOLV.FullRowSelect = true;
            this.fastOLV.UseCompatibleStateImageBehavior = false;
            fastOLV.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize);
            //姓名.FillsFreeSpace = true;


            //过滤
            this.fastOLV.UseFiltering = true;
            this.fastOLV.EmptyListMsg = "筛选的信息为空值";
            //可编辑
            this.fastOLV.CellEditActivation = ObjectListView.CellEditActivateMode.SingleClick;
            //颜色交替
            this.fastOLV.AlternateRowBackColor = Color.FromArgb(192, 255, 192);
            this.fastOLV.UseAlternatingBackColors = true;
            this.fastOLV.MultiSelect = true;//多项选择
            //拖拽
            //this.AllowDrop = true;
            //this.fastOLV.DragSource = new SimpleDragSource();
            //this.fastOLV.DropSink = new RearrangingDropSink(true);
            ////////////////////////////////////////////////////////
            OLVColumn ageCol = new OLVColumn();
            ageCol.AspectName = "Age";
            ageCol.Text = "年龄";
            ageCol.Groupable = true;

            ageCol.IsEditable = false;
            this.fastOLV.Columns.Add(ageCol);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<Person> list = new List<Person>(); 
            for(int i = 0; i <= 50000; i++)
            {
                list.Add(new Person() { Name = $"{i} 李华丽", Occu = $"1111-{i}", Age = i }); 
            }
            this.fastOLV.SetObjects(list);
        }

        private void txtFilter_TextChanged(object sender, EventArgs e)
        {
            TextMatchFilter filter = null;
            if (!string.IsNullOrEmpty(txtFilter.Text))
            {
                filter = TextMatchFilter.Prefix(this.fastOLV, txtFilter.Text.Trim());
            }
            if(fastOLV.DefaultRenderer==null)
                fastOLV.DefaultRenderer=new HighlightTextRenderer(filter);
            fastOLV.AdditionalFilter = filter;
            //this.fastOLV.UseFiltering = true;
            //this.fastOLV.Refresh();
            //this.Update();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            this.fastOLV.RemoveObjects(this.fastOLV.SelectedObjects);
            //bool isControlKeyDown = ((Control.ModifierKeys & Keys.Control) == Keys.Control);
            //if (isControlKeyDown)
            //    this.ListView.ClearObjects();
            //else
                //this.ListView.RemoveObjects(this.ListView.SelectedObjects);
        }

        private void btnDisable_Click(object sender, EventArgs e)
        {
            this.fastOLV.DisableObjects(this.fastOLV.SelectedObjects);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            this.fastOLV.ShowGroups = chkGroup.Checked;
        }
    }

    public class Person
    {
        public string Name { get; set; }
        public string Occu { get; set; }
        public int Age { get; set; }
    }
}
